%
% This generates a fuzzy number expressed in interval notation as a 2 row, N column vector
% x(:,1) represents the lower bounds of the intervals, x(:,2) represents the upper bounds.
% Thus x(n,:) is a 1 by 2 vector representing an interval of confidence
% x(1,:) is the span of the set.
% x(N,:) is the flat top of the trapezoid
% The values are distributed (as) equally (as possible giving floating point limitations)
% between low and peak1 and high and peak2 respectively.
% N is the granularity as mentioned above, and defaults to 1000.
% Though this is called fuzzy_trapezoid, the alpha values of each interval is not explicitly
% defined; thus this could be used in conjuction with an alpha generator to produce nonnormal,
% non-trapezoidal fuzzy sets abiet only convex ones with flat tops 
% where uniform granularity on the universe of discource is sufficient.
%

function x = fuzzy_trapezoid(low, peak1, peak2, high, N)

if(~exist('N'))
	N = 1000;
end

if (low > peak1)
	error('lower support is greater than the corresponding peak');
end

if(high < peak2)
	error('higher support is lesser than the corresponding peak');
end

if(peak1 > peak2)
	error('lower peak is greater than the higher peak');
end

if(low == peak1)
	x(:,1) = repmat(low, [N,1]);
else
	x(:,1) = [low:(peak1-low)/(N-1):peak1].';
	x(end,1) = peak1; % deal with floating point bullshit
end

if high == peak2
	x(:,2) = repmat(high, [N,1]);
else
	x(:,2) = [high:-(high-peak2)/(N-1):peak2].';
	x(end,2) = peak2;
end
